// dataInfo/index/index.js
import http from '../../http'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		active: 0,
		allData: {},

		lightChange: 0,
		screenChange: 0,
		cameraChange: 0,
		audioChange: 0,
		monitoringChange: 0,
		loopChange: 0,
	},
	onChange(event) {
		if (event.detail.index == 0) {
			this.setData({
				lightChange: this.data.lightChange + 1
			})
		}else if(event.detail.index == 1){
			this.setData({
				screenChange: this.data.screenChange + 1
			})
		}else if(event.detail.index == 2){
			this.setData({
				cameraChange: this.data.cameraChange + 1
			})
		}else if(event.detail.index == 3){
			this.setData({
				audioChange: this.data.audioChange + 1
			})
		}else if(event.detail.index == 4){
			this.setData({
				monitoringChange: this.data.monitoringChange + 1
			})
		}else if(event.detail.index == 5){
			this.setData({
				loopChange: this.data.loopChange + 1
			})
		}
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {

	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {
		let pages = getCurrentPages()
		console.log(pages);
		let currentPage = pages[pages.length - 1]
		let options = currentPage.options
		let date = new Date();
		let year = date.getFullYear();
		let month = (date.getMonth() + 1).toString().padStart(2, "0");
		let day = date.getDate().toString().padStart(2, "0");
		let endDate = year + "-" + month + "-" + day;
		let oneDay = 7 * 24 * 60 * 60 * 1000;
		let endTime = new Date(Date.now() - oneDay);
		let year1 = endTime.getFullYear();
		let month1 = (endTime.getMonth() + 1).toString().padStart(2, "0");
		let day1 = endTime.getDate().toString().padStart(2, "0");
		let startDate = year1 + "-" + month1 + "-" + day1;
		http.post({
			url: '/zg/iot-links/index/lineChart',
			data: {
				projectId: options.projectId,
				property: "brightness",
				timestamp: [startDate, endDate],
			},
			then: (res) => {
				console.log("数据", res.data);
				this.setData({
					allData: res.data.data,
					lightChange: this.data.lightChange + 1
				})
			}
		})
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})